//task_houseSurvey.js
const util = require("../../utils/util.js");
var Util = require('../../utils/util.js');

const app = getApp()

Page({
  data: {
    order_id: '',
    // 选中的任务类型
    selectedTask_type: "房屋勘测",
    // 任务时间
    taskTime: "",
    // 住宅位置
    taskAddress: "",
    // 装修日期
    installTime: "",
    // 房屋面积
    houseArea: "",
    // Wi-Fi信号
    wifiInfo: "",
    // 输入路由器型号
    routerMode: "",
    // 输入物料需求
    materialRequir: "",
    // 输入勘测备注
    surveyNotes: "",
    // 安装方式
    installModeArray: [{ id: 0, name: "玻璃" }, { id: 0, name: "水钻" }, { id: 0, name: "玻璃和水钻" }],

    // 存放勘测表
    selectedSurvey: "",
    surveyUpload: "",
    // 存放本地图片路径
    tempFilePaths: [],
    // 存放图片上传路径
    imagesUpload: [],

    // 存放房间信息的数组
    task_inputHouseArray: [{
      "machineId": "",
      "houseName": "",
      materielArray: [{
        "materielCount": "", "materielNameIndex": 0, "materielViewId": "",
        "glassLeft": "", "glassTop": "", "glassLength": "", "glassHeight": "", "glassThickness": "", "glassLayers": "", "glassRadius": "", "bracketHeight": "",
        "boliClassStr": "", "boliClassIndex": 0
      }],
      "isFirst": 0,
      "houseIndex": 0,
      "installModeIndex": 0,
      "installMode": "玻璃"
    }],
    // 存放物料名称的数组
    materielNameArr: [],
    materielSelect: 0,
    // 是否是玻璃：1:显示玻璃图片；0:不显示玻璃图片
    task_glassSelect: 0,

    // 今天的时间
    date: "",
    // 家庭人数
    personNum: "",
    // 是否有孩子
    isHaveChild: 1, // 1：有，0：无
    isHaveChildArray: ["无", "有"],
    // 孩子年龄段
    age: "",
    // 玻璃品类
    boliClassArr: ["普通玻璃", "特殊玻璃", "玻璃板", "用户自己做玻璃"]
  },
  onLoad(options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({
      order_id: options.id
    })

    this.setData({
      taskTime: options.time
    })
    this.setData({
      taskAddress: options.address
    })

    console.log("上门安装：id=" + this.data.order_id + 'address=' + this.data.taskAddress + 'time=' + this.data.taskTime);
    this.$wuxToast = app.wux(this).$wuxToast;
    this.refreshNewData();
    // 获取物料数组
    this.getMaterielList();

    //今天的时间
    var todayDate = new Date();

    todayDate.setTime(todayDate.getTime());
    var today_month = todayDate.getMonth() + 1;
    if (today_month < 10) {
      today_month = "0" + today_month;
    }
    var today_date = todayDate.getDate();
    if (today_date < 10) {
      today_date = "0" + today_date;
    }
    var todayDateStr = todayDate.getFullYear() + "-" + today_month + "-" + today_date;

    this.setData({
      date: todayDateStr,
      installTime: todayDateStr,
    })

  },
  // 家庭人数
  bindPersonNumChange: function (e) {
    this.setData({
      personNum: e.detail.value
    })
  },
  // 是否有孩子
  bindIsHaveChildChange: function (e) {
    if (this.data.isHaveChild == 1) {
      this.setData({
        isHaveChild:0
      })
    } else {
      this.setData({
        isHaveChild: 1
      })
    }
    
  },
  // 孩子年龄段
  bindAgeChange: function (e) {
    this.setData({
      age: e.detail.value
    })
  },
  // 选取装修日期
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value,
      installTime: e.detail.value
    })
  },
  // 输入房屋面积
  inputHouseArea: function (e) {
    this.setData({
      houseArea: e.detail.value
    })
  },
  // 输入路由器型号
  inputRouterMode: function (e) {
    this.setData({
      routerMode: e.detail.value
    })
  },
  // 输入物料需求
  inputMaterialRequir: function (e) {
    this.setData({
      materialRequir: e.detail.value
    })
  },
  //输入勘测备注
  inputSurveyNotes: function (e) {
    this.setData({
      surveyNotes: e.detail.value
    })
  },
  //输入安装方式
  inputWiFiInfo: function (e) {
    this.setData({
      wifiInfo: e.detail.value
    })
  },

  // 房间信息输入框
  house_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;

    this.data.task_inputHouseArray[index].houseName = value;
    console.log("this.data.task_inputHouseArray", this.data.task_inputHouseArray);
    this.setData({
      task_inputHouseArray: this.data.task_inputHouseArray
    })
  },
  // 添加房间
  insert_taskHousk: function () {
    console.log("添加订单");
    var firstMaterielID = this.data.materielNameArr[0].viewId;
    var firstBoliClassStr = this.data.boliClassArr[0];
    var newarray = [{
      "machineId": "", "houseName": "", "installModeIndex": 0, "installMode": "玻璃", materielArray: [{
        "materielCount": "", "materielNameIndex": 0, "materielViewId": firstMaterielID,
        "glassLeft": "", "glassTop": "", "glassLength": "", "glassHeight": "", "glassThickness": "", "glassLayers": "", "glassRadius": "", "bracketHeight": "",
        "boliClassStr": firstBoliClassStr, "boliClassIndex": 0
      }], "houseIndex": this.data.task_inputHouseArray.length
    }];
    this.data.task_inputHouseArray = this.data.task_inputHouseArray.concat(newarray);

    this.setData({
      task_inputHouseArray: this.data.task_inputHouseArray
    });

    this.$wuxToast.show({
      type: 'text',
      timer: 1000,
      color: '#fff',
      text: '房屋添加成功',
      success: () => console.log('文本内容')
    })
  },

  // 长按删除房间
  longTapDelateHouse: function (e) {
    var index = e.currentTarget.dataset.index;

    var selectItem = index + 1;
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否确定删除房间' + selectItem + '全部信息?',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');

          var completeDeleteArray = that.data.task_inputHouseArray;

          if (index == 0) {
            that.$wuxToast.show({
              type: 'text',
              timer: 1000,
              color: '#fff',
              text: '第一个房间不能删除',
              success: () => console.log('提交成功')
            });
            return;
          }
          completeDeleteArray.splice(index, 1);

          that.setData({
            task_inputHouseArray: completeDeleteArray
          });
          console.log(that.data.task_inputHouseArray);

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  // 长按删除物料信息
  longTapDelateMaterielItem: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    console.log("物料信息：index ===" + index + "; houseIndex==" + houseIndex);

    var selectItem = houseIndex + 1;
    var selectMaterial = that.data.task_inputHouseArray[houseIndex].materielArray[index].name;

    wx.showModal({
      title: '提示',
      content: '是否确定删除房间' + selectItem + '的该物料信息?',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');

          var completeDeleteArray = that.data.task_inputHouseArray;

          if (index == 0) {
            that.$wuxToast.show({
              type: 'text',
              timer: 1000,
              color: '#fff',
              text: '第一个物料不能删除',
              success: () => console.log('提交成功')
            });
            return;
          }
          completeDeleteArray[houseIndex].materielArray.splice(index, 1);

          that.setData({
            task_inputHouseArray: completeDeleteArray
          });
          console.log(that.data.task_inputHouseArray);

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })


  },
  // 选择安装方式
  bindInstallModeChange: function (e) {
    var index = e.detail.value;
    var parentIndex = e.currentTarget.dataset.index;

    this.data.task_inputHouseArray[parentIndex].installModeIndex = index;
    this.data.task_inputHouseArray[parentIndex].installMode = this.data.installModeArray[index].name;

    this.setData({
      task_inputHouseArray: this.data.task_inputHouseArray
    })
    
  },
  // 选择物料名称
  bindMaterielChange: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;

    var materielViewIdStr = this.data.materielNameArr[value].viewId;
    console.log("选中的viewId是：" + materielViewIdStr);
    this.data.task_inputHouseArray[houseIndex].materielArray[index].materielNameIndex = value;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].materielViewId = materielViewIdStr;

    // 修改全局变量
    this.setData({
      task_inputHouseArray: this.data.task_inputHouseArray,
      materielSelect: 1
    })
  },
  // 选择玻璃品类
  bindBoliClassChange: function(e){
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;

    var boliClassStr = this.data.boliClassArr[value];
    console.log("选中的玻璃分类是：" + boliClassStr);
    this.data.task_inputHouseArray[houseIndex].materielArray[index].boliClassIndex = value;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].boliClassStr = boliClassStr;

    // 修改全局变量
    this.setData({
      task_inputHouseArray: this.data.task_inputHouseArray,
      materielSelect: 1
    })
  },
  // 物料信息输入框
  materiel_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    console.log("物料信息：index ===" + index + "; houseIndex==" + houseIndex);

    this.data.task_inputHouseArray[houseIndex].materielArray[index].materielCount = value;

    // 修改全局变量
    this.setData({
      task_inputHouseArray: this.data.task_inputHouseArray
    })
  },
  // 添加物料
  insert_taskMateriel: function (e) {
    var index = e.currentTarget.dataset.index;
    var firstMaterielID = this.data.materielNameArr[0].viewId;
    var firstBoliClassStr = this.data.boliClassArr[0];
    var newarray = [{
      "materielCount": "", "materielNameIndex": 0, "materielViewId": firstMaterielID,
      "glassLeft": "", "glassTop": "", "glassLength": "", "glassHeight": "", "glassThickness": "", "glassLayers": "", "glassRadius": "", "bracketHeight": "", "boliClassStr": firstBoliClassStr, "boliClassIndex": 0
    }];
    var selectedHouse = this.data.task_inputHouseArray[index];
    this.data.task_inputHouseArray[index].materielArray = selectedHouse.materielArray.concat(newarray);

    this.setData({
      task_inputHouseArray: this.data.task_inputHouseArray
    });

    this.$wuxToast.show({
      type: 'text',
      timer: 1000,
      color: '#fff',
      text: '物料添加成功',
      success: () => console.log('文本内容')
    })
  },
  // 支架高度 
  bracketHeight_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].bracketHeight = value;
    console.log("支架高度：" + value);
  },
  // 玻璃高度
  glassLength_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].glassLength = value;
    console.log("玻璃高度：" + value);
  },
  // 玻璃宽度
  glassHeight_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].glassHeight = value;
    console.log("玻璃宽度：" + value);
  },
  // 玻璃厚度
  glassThickness_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].glassThickness = value;
    console.log("玻璃厚度：" + value);
  },
  // 玻璃层数
  glassLayers_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].glassLayers = value;
    console.log("玻璃层数：" + value);
  },
  // 孔距左
  glassLeft_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].glassLeft = value;
    console.log("玻璃距左距离：" + value);
  },
  // 孔距右
  glassTop_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].glassTop = value;
    console.log("玻璃距上距离：" + value);
  },
  // 孔径
  glassRadius_bindinput: function (e) {
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    var houseIndex = e.currentTarget.dataset.houseindex;
    this.data.task_inputHouseArray[houseIndex].materielArray[index].glassRadius = value;
    console.log("孔径：" + value);
  },
  // 勘察表图片查看
  showImage: function (event) {
    var that = this;

    wx.previewImage({
      current: that.data.surveyUpload, // 当前显示图片的http链接
      urls: [that.data.surveyUpload] // 需要预览的图片http链接列表
    })
  },
  // 选择勘察表
  upload_survey: function () {
    var _this = this;

    wx.chooseImage({
      count: 1, // 默认9  
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        util.showLoading();
        wx.uploadFile({
          url: app.globalData.BaseURL + '/fileUpload/image',
          filePath: res.tempFilePaths[0],
          name: 'file',
          success: function (res) {
            var state = JSON.parse(res.data).state;
            if (state == "success") {
              var url = JSON.parse(res.data).url;
              // 替换勘察表
              _this.setData({
                surveyUpload: url,
                selectedSurvey: "上传成功"
              })
            } else {
              _this.$wuxToast.show({
                type: 'text',
                timer: 1500,
                color: '#fff',
                text: '图片上传失败，请重新选择',
                success: () => console.log('文本内容')
              })
            }
            console.log("上传成功");
            console.log(JSON.parse(res.data));
            console.log(JSON.parse(res.data).url);
          },
          fail: function (res) {
            console.log("上传失败：" + res.data);
            _this.$wuxToast.show({
              type: 'text',
              timer: 1500,
              color: '#fff',
              text: '图片上传失败，请重新选择',
              success: () => console.log('文本内容')
            })
          }, complete: function () {
            util.hideToast();
          }
        })
      }
    })
  },
  // 查看上传图片
  uploadImageShowAction: function (event) {
    var index = event.currentTarget.dataset.index;
    var that = this;
    var currentUrl = that.data.imagesUpload[index];

    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: that.data.imagesUpload // 需要预览的图片http链接列表
    })
  },
  // 选择图片
  chooseimage: function () {
    var _this = this;
    var imagePaths = this.data.tempFilePaths;
    var uploadImagePaths = this.data.imagesUpload;

    wx.chooseImage({
      count: 9, // 默认9  
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        // 新选择图片的本地路径
        var filePathsArray = res.tempFilePaths;
        wx.showToast({
          title: '上传中...',
          icon: 'loading',
          mask: true,
          duration: 20000000
        });

        filePathsArray.forEach(function (item, index) {
          wx.uploadFile({
            url: app.globalData.BaseURL + '/fileUpload/image',
            filePath: item,
            name: 'file',
            success: function (res) {
              var state = JSON.parse(res.data).state;
              if (state == "success") {
                var url = JSON.parse(res.data).url;
                // 存放图片上传路径数组加1️
                uploadImagePaths.push(url);
                _this.setData({
                  imagesUpload: uploadImagePaths
                })
                // 存放本地图片路径数组加1️
                imagePaths.push(item);
                _this.setData({
                  tempFilePaths: imagePaths
                })
                if (index == filePathsArray.length - 1) {
                  wx.hideToast();
                }
              } else {
                wx.hideToast();
                _this.$wuxToast.show({
                  type: 'text',
                  timer: 1500,
                  color: '#fff',
                  text: '图片上传失败，请重新选择',
                  success: () => console.log('文本内容')
                })
              }
              console.log("上传成功");
              console.log(JSON.parse(res.data));
              console.log(JSON.parse(res.data).url);
            },
            fail: function (res) {
              wx.hideToast();
              console.log("上传失败：" + res.data);
              _this.$wuxToast.show({
                type: 'text',
                timer: 1500,
                color: '#fff',
                text: '图片上传失败，请重新选择',
                success: () => console.log('文本内容')
              })
            }, complete: function () {

            }
          });
        });

      }
    })
  },
  // 提交任务，参数信息
  loadSubmitDatas: function () {
    var that = this;
    var houseAreaStr = this.data.houseArea;
    var installStr = this.data.installTime;
    var wifiInfoStr = this.data.wifiInfo;
    var routerModeStr = this.data.routerMode;

    var surveyNotesStr = this.data.surveyNotes;
    var surverUrlStr = this.data.surveyUpload;
    var surveyImagesArr = this.data.imagesUpload;

    console.log("surveyImages=====", surveyImagesArr);

    var materialRequirData = this.data.task_inputHouseArray;
    var materialRequirStr = JSON.stringify(materialRequirData);

    console.log("勘察表：" + this.data.surveyUpload);
    console.log("安装位置图片：" + this.data.imagesUpload);

    console.log("房屋面积:" + houseAreaStr + "装修日期:" + installStr + "Wi-Fi信号情况:" + wifiInfoStr + "路由器型号:" + routerModeStr + "勘测备注:" + surveyNotesStr + "物料需求:" + materialRequirStr);

    var personNum = this.data.personNum;
    var isHaveChild = this.data.isHaveChild;
    var age = this.data.age;
    console.log("家庭人数:" + personNum);
    console.log("是否有孩子:" + isHaveChild);
    console.log("孩子年龄段:" + age);

    var dataSource = Util.json2Form({
      taskId: that.data.order_id,
      houseArea: houseAreaStr,
      decorationTime: installStr,
      wifiStatus: wifiInfoStr,
      routerMode: routerModeStr,
      materielRequirement: materialRequirStr,
      remark: surveyNotesStr,
      surveyUrl: surverUrlStr,
      surveyImages: surveyImagesArr,
      personNum: personNum,
      isHaveChild: isHaveChild,
      age: age
    });
    return dataSource;
  },
  // 提交表单按钮
  submitInfo: function () {
    // 刷新数据、加载提示框
    util.showLoading();
    var that = this;
    var pages = getCurrentPages()
    // var prevPage = pages[pages.length-1]  //当前界面
    var prevPage = pages[pages.length - 2]  //上一个页面
    // 接口传参
    var dataSource = this.loadSubmitDatas();
    console.log("提交任务信息：", dataSource);
    // 请求接口
    var urlString = app.globalData.BaseURL + '/api/task/addSurveyReport';
    wx.request({
      method: "POST",
      url: urlString,
      data: dataSource,
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'adminUserViewId': app.globalData.adminUserViewId,
        'token': app.globalData.token
      },
      success: function (res) {
        util.hideToast();
        console.log("data=======" + res.data);
        var code = res.data.code;

        if (code === 200) {
          that.$wuxToast.show({
            type: 'text',
            timer: 1000,
            color: '#fff',
            text: '上传成功',
            success: () => console.log('提交成功')
          });
          // 更改前一页面列表页的refreshLish属性，让其出现时刷新页面
          prevPage.setData({
            refreshLish: "true"
          });
          setTimeout(function () {
            wx.navigateBack({});
          }, 1000);
        } else {
          that.$wuxToast.show({
            type: 'text',
            timer: 1000,
            color: '#fff',
            text: res.data.msg,
            success: () => console.log('上传失败，请重新提交。')
          });
        }
      },
      fail: function () {
        that.$wuxToast.show({
          type: 'text',
          timer: 1000,
          color: '#fff',
          text: '网络错误，请稍后重试。',
          success: () => console.log('网络错误，请稍后重试。')
        })
      }, complete: function () {
        util.hideToast();
      }
    })
  },
  // 跳至安装
  submitJupInstallInfo: function () {
    // 刷新数据、加载提示框
    util.showLoading();
    var that = this;
    var pages = getCurrentPages()
    // var prevPage = pages[pages.length-1]  //当前界面
    var prevPage = pages[pages.length - 2]  //上一个页面
    // 接口传参
    var dataSource = this.loadSubmitDatas();
    console.log("提交任务信息：", dataSource);
    // 请求接口
    var urlString = app.globalData.BaseURL + '/api/task/addSurveyReportToInstall';
    wx.request({
      method: "POST",
      url: urlString,
      data: dataSource,
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'adminUserViewId': app.globalData.adminUserViewId,
        'token': app.globalData.token
      },
      success: function (res) {
        util.hideToast();
        console.log("data=======" + res.data);
        var code = res.data.code;

        if (code === 200) {
          that.$wuxToast.show({
            type: 'text',
            timer: 1000,
            color: '#fff',
            text: '上传成功',
            success: () => console.log('提交成功')
          });
          // 更改前一页面列表页的refreshLish属性，让其出现时刷新页面
          prevPage.setData({
            refreshLish: "true"
          });
          setTimeout(function () {
            wx.navigateBack({});
          }, 1000);
        } else {
          that.$wuxToast.show({
            type: 'text',
            timer: 1000,
            color: '#fff',
            text: res.data.msg,
            success: () => console.log('上传失败，请重新提交。')
          });
        }
      },
      fail: function () {
        that.$wuxToast.show({
          type: 'text',
          timer: 1000,
          color: '#fff',
          text: '网络错误，请稍后重试。',
          success: () => console.log('网络错误，请稍后重试。')
        })
      }, complete: function () {
        util.hideToast();
      }
    })
  },
  // 任务失败跳转
  taskFailedAction: function () {
    var that = this;
    console.log("失败 taskId=" + that.data.order_id);
    wx.navigateTo({
      url: '/pages/task_failed/task_failed' + '?id=' + that.data.order_id + '&time=' + that.data.taskTime + '&address=' + that.data.taskAddress + '&task_type=' + that.data.selectedTask_type
    })
  },
  //加载物料列表
  getMaterielList: function () {
    var that = this;
    var urlStr = '/api/task/getMaterielList';
    var parameters = "";
    util.request(urlStr, parameters, function (res) {
      console.log("data===" + res);
      var materielArray = res.data.data;
      console.log("materielArray===" + materielArray);
      that.setData({
        materielNameArr: materielArray
      });

      var materielViewIdStr = that.data.materielNameArr[0].viewId;
      console.log("选中的viewId是：" + materielViewIdStr);
      that.data.task_inputHouseArray[0].materielArray[0].materielViewId = materielViewIdStr;

      // 修改全局变量
      that.setData({
        task_inputHouseArray: that.data.task_inputHouseArray
      })

    })
  }, complete: function () {
    util.hideToast();
  },
  //刷新数据
  refreshNewData: function () {
    //加载提示框
    util.showLoading();
    var that = this;
    var urlStr = '/api/task/' + this.data.order_id;
    var parameters = "";
    util.request(urlStr, parameters, function (res) {
      console.log("data===" + res.data);
      util.hideToast();
      var startTime = res.data.data.task.startTime;
      if (startTime == "" || startTime == undefined) {
        // 未开始任务，提示先开始任务
        wx.showModal({
          title: '该任务暂未开始',
          content: '请返回首页开始任务，再提交任务信息',
          cancelText: '暂不开始',
          confirmText: '立即返回',
          success: function (res) {
            if (res.confirm) {
              console.log("确认返回首页");
              wx.navigateBack({})
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    })
  }, complete: function () {
    util.hideToast();
  }
})